<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

$api = app('Dingo\Api\Routing\Router');

$api->version('v1', function (\Dingo\Api\Routing\Router $api) {

    $api->any('/', 'App\Http\Controllers\IndexController@index');
    $api->any('/district', 'App\Http\Controllers\IndexController@region');

    $api->post('/auth/login', 'App\Http\Controllers\AuthController@login');

    // 上传文件
    $api->post('/upload', 'App\Http\Controllers\UploadController@upload');

    // 需要用户登录路由
    $api->group(['middleware' => 'api.auth'], function (\Dingo\Api\Routing\Router $api) {
        // 用户信息
        $api->get('/userinfo', 'App\Http\Controllers\AuthController@info');

        // 部门管理
        $api->get('/department', 'App\Http\Controllers\DepartmentController@search');
        $api->get('/department/{id}', 'App\Http\Controllers\DepartmentController@show');
        $api->post('/department', 'App\Http\Controllers\DepartmentController@create');
        $api->put('/department/{id}', 'App\Http\Controllers\DepartmentController@update');
        $api->delete('/department/{id}', 'App\Http\Controllers\DepartmentController@delete');

        // 角色管理
        $api->get('/roles', 'App\Http\Controllers\RoleController@search');
        $api->get('/roles/{id}', 'App\Http\Controllers\RoleController@show');
        $api->post('/roles', 'App\Http\Controllers\RoleController@create');
        $api->put('/roles/{id}', 'App\Http\Controllers\RoleController@update');
        $api->delete('/roles/{id}', 'App\Http\Controllers\RoleController@delete');

        // 权限
        $api->get('/permissions', 'App\Http\Controllers\RoleController@permissions');

        // 用户管理
        $api->get('/user', 'App\Http\Controllers\UserController@search');
        $api->get('/user-tree', 'App\Http\Controllers\UserController@tree');
        $api->get('/user/{id}', 'App\Http\Controllers\UserController@show');
        $api->post('/user', 'App\Http\Controllers\UserController@create');
        $api->post('/user/freeze', 'App\Http\Controllers\UserController@freeze');
        $api->put('/user/{id}', 'App\Http\Controllers\UserController@update');
        $api->delete('/user/{id}', 'App\Http\Controllers\UserController@delete');

        // 客户管理
        $api->get('/customer', 'App\Http\Controllers\CustomerController@search');
        $api->post('/customer', 'App\Http\Controllers\CustomerController@create');
        $api->post('/customer/move', 'App\Http\Controllers\CustomerController@move');
        $api->get('/customer/{id}', 'App\Http\Controllers\CustomerController@show');
        // 客户跟踪
        $api->get('/customer_record', 'App\Http\Controllers\CustomerController@records');
        $api->post('/customer_record', 'App\Http\Controllers\CustomerController@follow');

        // 客户分配路由
        $api->post('/customer/import', 'App\Http\Controllers\CustomerController@import');
        $api->get('/customer/import/list', 'App\Http\Controllers\CustomerController@importList');
        $api->post('/customer/import/confirm', 'App\Http\Controllers\CustomerController@confirmAssigned');
        $api->post('/customer/import/delete', 'App\Http\Controllers\CustomerController@assignedDelete');

        // 团队目标
        $api->get('/team/goals', 'App\Http\Controllers\TeamGoalsController@search');
        $api->post('/team/batch_create', 'App\Http\Controllers\TeamGoalsController@batchCreate');

        // 工作日历
        $api->get('/work/calendar', 'App\Http\Controllers\WorkController@calendar');
        $api->get('/work/day', 'App\Http\Controllers\WorkController@create');
        $api->get('/work/get_data', 'App\Http\Controllers\WorkController@dayData');
        $api->post('/work/create', 'App\Http\Controllers\WorkController@create');


        // 统计数据
        $api->get('/statistical/work-data', 'App\Http\Controllers\StatisticalController@workData');

    });
});
